#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;

struct Book
{
	int a, b, c;
}p[N];

bool cmp(Book x, Book y) {
	if (x.a == y.a && x.b == y.b) return x.c > y.c;
	if (x.a == y.a) return x.b > y.b;
	return x.a > y.a;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i].a >> p[i].b >> p[i].c;
	}
	sort(p + 1, p + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		cout << p[i].a << " " << p[i].b << " " << p[i].c << '\n';
	}
	return 0;
}